package com.itheima.controller;


import com.itheima.autoconfig.oss.OssTemplate;
import com.itheima.common.R;
import com.itheima.vo.OssResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class OssController {

    @Autowired
    OssTemplate ossTemplate;


    @RequestMapping(value = "/aliyun/oss/upload",method = RequestMethod.POST)
    public R upload(MultipartFile photoFile) throws IOException {
        //1.获取文件名
        String filename = photoFile.getOriginalFilename();
        String url = ossTemplate.upload(filename, photoFile.getInputStream());
        OssResult ossResult = new OssResult(url);
        return R.success(ossResult);
    }
}
